﻿namespace Assets.Scripts.Example5
{
    public class PoolTestEntity : BaseBehaviour
    {
        public ObjectPoolWithReset<Vector3Wrapper> vectorPool = new ObjectPoolWithReset<Vector3Wrapper>(2000);
        public ObjectPoolWithReset<Message> messagePool = new ObjectPoolWithReset<Message>(2000);

        public void OnUpdate(bool usePool)
        {
            
            if (usePool)
            {
                var msg = messagePool.New();
                msg.m_PlayerID = 0;
                var pos = vectorPool.New();
                msg.m_Pos = pos;
                vectorPool.Store(pos);
                messagePool.Store(msg);
            }
            else
            {
                var msg = new Message();
                msg.m_PlayerID = 0;
                var pos = new Vector3Wrapper();
                msg.m_Pos = pos;
            }
        }
    }

    /// <summary>
    ///     消息.
    /// </summary>
    public class Message:IResetable
    {
        public int m_PlayerID;
        public Vector3Wrapper m_Pos;
        public void Reset()
        {
            m_PlayerID = 0;
            m_Pos = null;
        }
    }

    /// <summary>
    ///     通用封装结构.
    /// </summary>
    public class Vector3Wrapper : IResetable
    {
        public float x;
        public float y;
        public float z;

        public Vector3Wrapper()
        {
        }

        public Vector3Wrapper(float x, float y, float z)
        {
            this.x = x;
            this.y = y;
            this.z = z;
        }

        public void Reset()
        {
            x = 0;
            y = 0;
            z = 0;
        }
    }
}